import type {
  CheckUserType,
  RegMobileType,
  codeType,
  resetLoginType,
} from '@/common/model/request';
import type { MainResponseType, configType } from '@/common/model/response';
import request from '@/utils/axios';

const URL = {
  CHECKUSER: 'index/checkUser',
  REGMOBILE: 'index/reg_mobile',
  VERIFICATIONCODE: 'index/SendVerificationCode',
  USERINFO: 'Api/getUserinfo',
  FORGETLOGIN: 'Api/forget_loginpaw',
  GETCONFIG: 'Api/getConfig',
  Graphiccode: 'Index/get_Graphiccode',
};

export function checkUser(data: CheckUserType) {
  return request.post<
    any,
    MainResponseType<{
      _token: string;
    }>
  >(URL.CHECKUSER, data);
}

export function regMobile(data: RegMobileType) {
  return request.post<any, MainResponseType<{ _token: string }>>(
    URL.REGMOBILE,
    data
  );
}
export function sendVerificationCode(data: codeType) {
  return request.post<any, MainResponseType<string>>(
    URL.VERIFICATIONCODE,
    data,
    {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
    }
  );
}

export function getUserinfo() {
  return request.get<
    any,
    MainResponseType<{
      user_id: number;
      nickname: string;
      mobile: string;
      level: number;
      level_name: string;
      avatar: string;
      mailbox: string;
      recharge_balance: number;
      withdraw_balance: number;
      is_setuppay: number;
    }>
  >(URL.USERINFO);
}
export function forget_loginpaw(data: resetLoginType) {
  return request.post<any, MainResponseType<string>>(URL.FORGETLOGIN, data);
}
export function getConfig() {
  return request.post<any, MainResponseType<configType>>(URL.GETCONFIG);
}
export function getGraphiccode(mobile: string, type?: '1' | '2') {
  return request.post<any, MainResponseType<string>>(
    URL.Graphiccode + `?mobile=${mobile}&type=${type}`
  );
}
